<html xmlns:th="http://www.thymeleaf.org" xmlns:shiro="http://www.pollix.at/thymeleaf/shiro" >
<link th:href="@{/layui/css/layui.css}" rel="stylesheet"/>
<head th:include="admin/common/resource ::commonHead('修改菜单')" ></head>
<style>
    .layui-form-item .layui-input-inline{
        margin-left: 30px;
    }
    .layui-form-item .layui-form-label{
        padding: 2px 0px;
    }
</style>
<script>
    function loadPage(url) {
        window.location.href = url;
    }
</script>
<head>
    <title>修改</title>
</head>

<body>

<div class="container" style="margin-left: 0px">
    <div class="toolbar btn-group-sm" role="toolbar" >
        <h6 style="margin-top: 10px;margin-bottom: 20px" > 后台管理系统 / 菜单管理 / 修改菜单 </h6>
        <div class="btn-group btn-group-toggle" data-toggle="buttons" style="margin-bottom: 16px">
            <label shiro:hasPermission="action:list" class="btn btn-secondary btn-sm" onclick="loadPage('/admin/action/list')">
                <input type="radio" name="options" id="option1" autocomplete="off" checked> 菜单列表
            </label>

            <label shiro:hasPermission="action:edit" class="btn btn-secondary btn-sm active">
                <input type="radio" name="options" id="option3" autocomplete="off"> 修改菜单
            </label>
        </div>
    </div>

    <form class="layui-form" action="/admin/action/save" method="post" enctype="multipart/form-data">
        <input type="hidden" name="id" th:value="${action.id}">
        <div class="layui-form-item">
            <label class="layui-form-label">菜单名称</label>
            <div class="layui-input-block">
                <input type="text" name="actionName" required  lay-verify="required" th:value="${action.actionName}" placeholder="请输入菜单标题"  class="layui-input">
            </div>
        </div>

        <div class="layui-form-item">
            <label class="layui-form-label">所属菜单</label>
            <div class="layui-input-block">
                <select name="parentId">
                    <option value="0">顶级菜单</option>
                    <option th:value="${act.id}" th:each="act:${parents}" th:text="${act.actionName}" th:selected="${act.id} == ${action.parentId}" ></option>
                </select>
            </div>
        </div>
        <!--<div class="layui-form-item">-->
            <!--<label class="layui-form-label">复选框</label>-->
            <!--<div class="layui-input-block">-->
                <!--<input type="checkbox" name="like[write]" title="写作">-->
                <!--<input type="checkbox" name="like[read]" title="阅读" checked>-->
                <!--<input type="checkbox" name="like[dai]" title="发呆">-->
            <!--</div>-->
        <!--</div>-->
        <div class="layui-form-item">
            <label class="layui-form-label"> URL </label>
            <div class="layui-input-block">
                <input class="layui-input" type="text" name="url" th:value="${action.url}" placeholder="请输入菜单url">
            </div>
        </div>

        <div class="layui-form-item">
            <label class="layui-form-label"> 权限code </label>
            <div class="layui-input-block">
                <input type="text" name="actionCode" class="layui-input" th:value="${action.actionCode}" placeholder="请输入权限code">
            </div>
        </div>

        <div class="layui-form-item">
            <div class="layui-input-block">
                <button class="layui-btn" lay-submit lay-filter="formDemo">立即提交</button>
                <button type="reset" class="layui-btn layui-btn-primary">重置</button>
            </div>
        </div>
    </form>
</div>

</body>
<script th:src="@{/layui/layui.all.js}"></script>
<script>

    //Demo
    layui.use('form', function(){
        var form = layui.form;

        //监听提交
        form.on('submit(formDemo)', function(data){
            $.ajax({
                url: "/admin/action/save",
                type:'post',
                data: JSON.stringify({
                    id:data.field.id,
                    actionName:data.field.actionName,
                    parentId:data.field.parentId,
                    url:data.field.url,
                    actionCode:data.field.actionCode,
                }),
                contentType: 'application/json',
                dataType: 'json',
                success: function (res) {
                    if(res.code == 1){
                        layer.msg("保存成功!",function () {
                            window.location.href = "/admin/action/list";
                        },2000)
                    }
                },
                error:function (err) {
                    layer.msg("保存失败")
                }
            })
            return false;
        });
    });
</script>
</html>